﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static LiWi.Shell;

namespace LiWiTools
{
    public partial class SetIP : Form
    {
        public bool IPChange = false;
        Data IPName;
        public SetIP(Data IP)
        {
            InitializeComponent();
            IPName = IP;
        }
        private void SetIP_Load(object sender, EventArgs e)
        {
            if(IPName.handle==IntPtr.Zero)
            {
                this.Close();
                MessageBox.Show("请先连接控制器");                
                return;
            }
            GetIP();
        }

        private void btn_change_Click(object sender, EventArgs e)
        {
            string ip = txt_NewIP.Text;
            int a=PMC_SetIp(IPName.handle, ip);
            if (a != 0) MessageBox.Show($"修改失败！！！返回值为：{a}");
            else
            {
                IPChange = true;
                //Thread.Sleep(1000);
                MessageBox.Show("修改完成");
                this.Close();
            }
        }

        /// <summary>
        /// 获取IP
        /// </summary>
        private void GetIP()
        {
            byte[] ipByte = new byte[16];
            PMC_GetIp(IPName.handle, ipByte);
            string ip = Encoding.UTF8.GetString(ipByte);
            lab_OldIP.Text = ip;
        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
